 <?php
	include("kn.php");
	$user = $_POST["user"];
	$pass = $_POST["pass"];
	if(isset($_POST["user"])&&isset($_POST["pass"]))
	{
		$lenh = "select * from khachhang where user = '$user' and matkhau = '$pass'";
		$kq = mysql_query($lenh);
		$n = mysql_num_rows($kq);
		if($n > 0)
		{
			$_SESSION["user"]=$user;
			?>
            <script>
			alert('Đăng nhập thành công!');			
			</script>            
            <?php
		}
		else
		{
			?>
            <script>
			alert('Đăng nhập thất bại!');
			</script>
            <?php
		}
		
	}
	if(!$_SESSION["user"])
	{
    echo"<form id='form1' name='form1' method='post' action=''>
  <table width='100%' border='0' cellspacing='0' cellpadding='0'>
    <tr>
      <td width='81' align='center'>User</td>
      <td width='119' align='center'><label for='user'></label>
      <input name='user' type='text' id='user' size='15'/></td>
    </tr>
    <tr>
      <td align='center'>Pass</td>
      <td align='center'><label for='pass'></label>
      <input name='pass' type='password' id='pass' size='15'/></td>
    </tr>
    <tr>
      <td height='30' colspan='2' align='center'><input type='submit' name='dn' id='dn' value='Đăng nhập' style=' padding-left:15px; padding-right:15px; background-color:#FCC;border-radius:10px 10px 10px 10px' /><br><a href=index.php?act=dk>Đăng ký</a> | <a href=index.php?act=qmk>Quên mật khẩu</a></td>
    </tr>
  </table>
</form>";
	}
	else
	{
		$lenh2 = "select * from khachhang where user = '".$_SESSION["user"]."'";
		$kq2 = mysql_query($lenh2);
		$row2 = mysql_fetch_assoc($kq2);
		$n2 = mysql_num_rows($kq2);
		if($n2 > 0)
		$_SESSION["Macv"]=$row2["Macv"];
		
		if($_SESSION["Macv"]==0)
		{
		echo "Chào ".$row2["Tenkhachhang"]."<br>";
		echo"<a href='thoatnew.php'>Thoát</a>";
		}
		else
		{
			echo "Chào ".$row2["Tenkhachhang"]."<br>";
		
		echo"<a href='index.php?act=qt'>Quản trị</a>"." | ";
		echo"<a href='thoatnew.php'>Thoát</a>";
			
		}
		
	}

?>
